package com.sec.etech.file.controller;

import cn.hutool.core.util.StrUtil;
import org.openbpm.base.api.aop.annotion.CatchErr;
import org.openbpm.base.api.response.impl.ResultMsg;
import org.openbpm.base.rest.ControllerTools;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping({"/v1/file/"})
public class FileController extends ControllerTools {
    @Resource
    JdbcTemplate jdbcTemplate;

    /**
     * 根据ids查询文件列表
     * @param fileId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = {"{fileId}"}, method = {RequestMethod.GET})
    @CatchErr("获取文件失败")
    public ResultMsg<List> getFileListByIds(@PathVariable("fileId") String fileId) throws Exception {
        if (StrUtil.isNotBlank(fileId)) {
            String sql = "SELECT id_ id,name_ name,create_by_ postuid FROM sys_file WHERE id_ in ('{}') ORDER BY id_ DESC ";
            List list = jdbcTemplate.queryForList(StrUtil.format(sql, StrUtil.join("','",StrUtil.split(fileId,","))));
            return new ResultMsg(list);
        }
        return new ResultMsg(new ArrayList<>());
    }
}
